﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BookStore.Solution.BLL;
using BookStore.Solution.Entities;
namespace BookStore.Solution.Presentation
{
    public partial class ucInventory : UserControl
    {
        public ucInventory()
        {
            InitializeComponent();
        }
        int quantity=0;long price=0;
        private DataTable CreateTable(List<Product> list)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ProductID", Type.GetType("System.String"));
            dt.Columns.Add("ProductName", Type.GetType("System.String"));
            dt.Columns.Add("Quatity", Type.GetType("System.Int32"));
            dt.Columns.Add("UnitPrice", Type.GetType("System.Int64"));
            foreach (Product a in list)
            {
                DataRow newrow = dt.NewRow();
                object[] array = new object[4];
                array[0] = a.ProductID;
                array[1] = a.ProductName;
                array[2] = a.Quatity;
                array[3] = a.UnitPrice;
                newrow.ItemArray = array;
                dt.Rows.Add(newrow);
                quantity += a.Quatity;
                price += a.Quatity * a.UnitPrice;
            }
            return dt;
        }
        private void inventory_Load(object sender, EventArgs e)
        {
            loadInvantory();
           txtPrice.Text = price.ToString();
           txtQuanTity.Text = quantity.ToString();
        }
        private void loadInvantory()
        {
            ProductManager products = new ProductManager();
            List<Product> pd = new List<Product>();
            pd = products.GetAll();
            DataTable table = CreateTable(pd);
            foreach (DataRow row in table.Rows)
            {
                dtgvListproduct.Rows.Add(row["ProductID"], row["ProductName"], row["Quatity"], row["UnitPrice"]);
            }
        }

    }
}
